package dgut.haitaobao.controller;

import dgut.haitaobao.service.UserService;
import dgut.haitaobao.util.response.HttpResponse;
import dgut.haitaobao.vo.param.UserLoginOrRegisterParamsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@CrossOrigin //允许跨域请求
public class UserController {

    @Autowired
    private UserService userService;

    /*用户登录*/
    @RequestMapping("/login")
    public HttpResponse userLogin(@RequestBody UserLoginOrRegisterParamsVO paramsVO){
        System.out.println(paramsVO);
        //System.out.println(userService.userLogin(paramsVO.getUsername(),paramsVO.getPassword()));
        return userService.userLogin(paramsVO.getUsername(),paramsVO.getPassword());
    }

    //用户注册
    @RequestMapping("/regist")
    public HttpResponse userRegist(@RequestBody UserLoginOrRegisterParamsVO paramsVO){
        System.out.println(paramsVO);
        return userService.userResgit(paramsVO.getUsername(),paramsVO.getPassword());
    }
}
